﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
namespace KornyezetVedelem
{
    class HulladekLerako : DAL
    {
        private DataSet dS;
        private String str;
        public HulladekLerako(ref bool Err)
        {
            if (!base.IsConnectCreated()) //ha a kapcsolat meg nem jott letre(meg nincs letrehozva)
            {
                Err = !base.MakeConnection();
            }
        }


        //feltolti a DataReader objektumot a Nyaralok tabla NyaraloNev oszlopok mezoivel
        public System.Data.SqlClient.SqlDataReader HulladekLerakoToltDR(ref string ErrM)
        {
            string sSQL = "SELECT * FROM HulladekLerako";
            myDataReader = base.myExecuteReader(sSQL, ref ErrM);
            return myDataReader;
        }
        public DataSet HulladekLerakoToltDS(ref string ErrM)
        {
           string sSQL = "SELECT * FROM HulladekLerako";
           dS = base.myExecuteReader_D(sSQL, ref ErrM);
           return dS;
        }
        public void Beszur(String Nev,int Nagysag,String Tipus)
        {
            string sSQL = "SELECT MAX( HulladekLerakoId) FROM HulladekLerako";
            int max = base.getMaximumId(sSQL)+1;
            sSQL = "INSERT INTO HulladekLerako values(" + max + "," + "'" + Nev + "'" + "," + Nagysag + "," + "'" + Tipus + "'" + ")";
            beszuras(sSQL);
        }
        public Exception Torol(String Id)
        {
            Exception ex1;
            String delSQL = "DELETE FROM HulladekLerako WHERE HulladekLerakoId = " + Convert.ToString(Id);
            ex1 = Torles(delSQL);
            return ex1;  

        }
        public void Modosit(String Id,String Nev, int Nagysag, String Tipus)
        {
            String sSQL = "Update HulladekLerako Set  HulladekLerakoNev = '" + Nev + "'" + "," + "Nagysag = " + Convert.ToString(Nagysag)  + "," + "Tipus = '" + Tipus + "'" + "Where HulladekLerakoID = " + Id;
            modositas(sSQL);
        }
        public DataSet Szuro(String s1,int ferohely,String tipus)
        {
            string sSQL= "SELECT * FROM HulladekLerako h ", s2 = "",s3="",s4="";
            if (s1 != "")
            {
                s2 = " where h.Hulladeklerakonev like '" + s1 + "%'";
                if (ferohely != -1)
                    s3 = " and h.Nagysag >" + ferohely;
                if (tipus != "")
                    s4 = " and h.tipus = '" + tipus + "'";
            }
            else
                if (ferohely != -1)
                {
                    s3 = " where h.Nagysag > " + ferohely;
                    if (tipus != "")
                        s4 = " and h.tipus = '" + tipus + "'";
                }
                else
                    if (tipus != "")
                        s4 = " where h.tipus = '" + tipus + "'";
            sSQL = sSQL + s2 +s3+s4;
            dS = myExecuteReader_D(sSQL, ref str);
            return dS;
        }
        public void feltoltCombo(ComboBox comboBox1)
        {
            MakeConnection();
            System.Data.SqlClient.SqlDataReader reader;
           
            string sSQL = "SELECT distinct tipus FROM HulladekLerako";
            reader = base.myExecuteReader(sSQL, ref str);
            while (reader.Read())
            {
                comboBox1.Items.Add(reader["Tipus"]);
            }
            reader.Close();
            CloseConnection();
        }
    }
}